package com.cloudcc.boot.entity.mdm;

import com.cloudcc.boot.enums.SuccessfulOrFailedEnum;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class EsbBatchResponse {

    private String batchId;

    private SuccessfulOrFailedEnum overallStatus;

    private List<EsbSingleResponse> items;

    public EsbBatchResponse(String batchId) {
        this.batchId = batchId;
        this.items = new ArrayList<>();
    }

    public void addItem(EsbSingleResponse item) {
        this.items.add(item);
    }

    public SuccessfulOrFailedEnum getOverallStatus() {
        return items.stream()
                .map(EsbSingleResponse::getStatus)
                .anyMatch(status -> !status.isSuccess())
                ? SuccessfulOrFailedEnum.FAILURE : SuccessfulOrFailedEnum.SUCCESS;
    }

}
